package cz.anime.ppro.beans;

import java.util.Calendar;
import java.util.Date;

import javax.faces.bean.ManagedBean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import cz.anime.ppro.logic.EventComponent;
import cz.anime.ppro.logic.UserComponent;
import cz.anime.ppro.model.Event;

@Component
@ManagedBean
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class CreateEventBean {

	@Autowired
	private EventComponent eventComponent;
	
	@Autowired
	private UserComponent userComponent;

	private Date eventDate;
	private String description;
	private String text;

	public String createEvent(){
		Event event = new Event();
		
		event.setDate(Calendar.getInstance().getTime());
		event.setEventDate(getEventDate());
		event.setDescription(getDescription());
		event.setText(getText());
		event.setWebuser(userComponent.getUserByNick(userComponent.getCurrentUsernameFromSession()));
		
		eventComponent.saveEvent(event);
		
		return "event-list?faces-redirect=true";
	}	

	public Date getEventDate() {
		return eventDate;
	}

	public void setEventDate(Date eventDate) {
		this.eventDate = eventDate;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

}
